package com.isyscore.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.isyscore.dto.PageInfoDto;
import com.isyscore.entity.admin.SysPost;
import com.isyscore.form.sys.post.ListPostForm;
import com.isyscore.service.admin.SysPostService;
import com.isyscore.utils.MesResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.ibatis.annotations.Delete;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

/**
 * <p>
 * 岗位信息表 前端控制器
 * </p>
 *
 * @author LGL
 * @since 2024年10月25日
 */
@RestController
@RequestMapping("/api/sysPost")
@Tag(name = "岗位管理", description = "岗位管理相关接口")
public class SysPostController {

    @Autowired
    private SysPostService sysPostService;

    @PostMapping("/list")
    @RequiresPermissions("system:post:list")
    @Operation(summary = "获取岗位列表")
    public MesResult list(@RequestBody ListPostForm form){
        IPage<SysPost> list = sysPostService.listPost(form);
        return MesResult.success(list);
    }
    @PostMapping("/add")
    @RequiresPermissions("system:post:add")
    @Operation(summary = "新增岗位")
    public MesResult add(@RequestBody SysPost post){
        //获取登录id
        Long userId = (Long) SecurityUtils.getSubject().getPrincipal();
        post.setCreateBy(userId.toString());
        boolean result = sysPostService.add(post);
        return MesResult.success(result);
    }
    @PutMapping("/edit")
    @RequiresPermissions("system:post:edit")
    @Operation(summary = "修改岗位")
    public MesResult edit(@RequestBody SysPost post){
        //获取登录id
        Object userId = SecurityUtils.getSubject().getPrincipal();
        post.setUpdateBy(userId.toString());
        boolean result = sysPostService.edit(post);
        return MesResult.success(result);
    }
    @DeleteMapping("/delete/{postId}")
    @RequiresPermissions("system:post:remove")
    @Operation(summary = "单条删除岗位")
    public MesResult delete(@PathVariable("postId") Long postId){
        boolean result = sysPostService.removeById(postId);
        return MesResult.success(result);
    }
    @DeleteMapping("/batchDelete")
    @RequiresPermissions("system:post:remove")
    @Operation(summary = "批量删除岗位")
    public MesResult delete(@RequestBody Long[] postIds){
        boolean result = sysPostService.removeByIds(Arrays.asList(postIds));
        return MesResult.success(result);
    }





}

